unit Class_To_Detail;



interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TToDetail=class(TUniEngine)
  private
    FBKFLHDJE : Extended;
    FBKFLUNIT : string;
    FBKFLZDID : string;
    FBKFLFDID : Integer;
    FQBFLHDJE : Extended;
    FQBFLUNIT : string;                      
    FQBFLZDID : string;
    FQBFLFDID : Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    //#function  GetNextIndx:Integer;overload;
    //#function  GetNextIndx(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property BKFLHDJE : Extended read FBKFLHDJE  write FBKFLHDJE;
    property BKFLUNIT : string read FBKFLUNIT  write FBKFLUNIT;
    property BKFLZDID : string read FBKFLZDID  write FBKFLZDID;
    property BKFLFDID : Integer read FBKFLFDID  write FBKFLFDID;
    property QBFLHDJE : Extended read FQBFLHDJE  write FQBFLHDJE;
    property QBFLUNIT : string read FQBFLUNIT  write FQBFLUNIT;
    property QBFLZDID : string read FQBFLZDID  write FQBFLZDID;
    property QBFLFDID : Integer read FQBFLFDID  write FQBFLFDID;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(aToDetail:TToDetail):TToDetail;overload;        
    class procedure CopyIt(aToDetail:TToDetail;var Result:TToDetail);overload;       
  end;

implementation

{ TToDetail }
procedure TToDetail.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('BKFL_HDJE').Value := BKFLHDJE;
        ParamByName('BKFL_UNIT').Value := BKFLUNIT;
        ParamByName('BKFL_ZDID').Value := BKFLZDID;
        ParamByName('BKFL_FDID').Value := BKFLFDID;
        ParamByName('QBFL_HDJE').Value := QBFLHDJE;
        ParamByName('QBFL_UNIT').Value := QBFLUNIT;
        ParamByName('QBFL_ZDID').Value := QBFLZDID;
        ParamByName('QBFL_FDID').Value := QBFLFDID; 
      end;
      otEdit:
      begin
        ParamByName('BKFL_HDJE').Value := BKFLHDJE;
        ParamByName('BKFL_UNIT').Value := BKFLUNIT;
        ParamByName('BKFL_ZDID').Value := BKFLZDID;
        ParamByName('BKFL_FDID').Value := BKFLFDID;
        ParamByName('QBFL_HDJE').Value := QBFLHDJE;
        ParamByName('QBFL_UNIT').Value := QBFLUNIT;
        ParamByName('QBFL_ZDID').Value := QBFLZDID;
        ParamByName('QBFL_FDID').Value := QBFLFDID; 
      end;  
      otDelt:
      begin
        ParamByName('BKFL_HDJE').Value := BKFLHDJE;
        ParamByName('BKFL_UNIT').Value := BKFLUNIT;
        ParamByName('BKFL_ZDID').Value := BKFLZDID;
        ParamByName('BKFL_FDID').Value := BKFLFDID;
 
      end;  
    end;
  end;
end;

function TToDetail.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_TO_DETAIL',['BKFL_HDJE',BKFLHDJE,'BKFL_UNIT',BKFLUNIT,'BKFL_ZDID',BKFLZDID,'BKFL_FDID',BKFLFDID],AUniConnection);
end;

{#function TToDetail.GetNextIndx: Integer;
begin

end;}

{#function TToDetail.GetNextIndx(AUniConnection: TUniConnection): Integer;
begin

end;}

function TToDetail.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_TO_DETAIL WHERE   BKFL_HDJE=:BKFL_HDJE AND BKFL_UNIT=:BKFL_UNIT AND BKFL_ZDID=:BKFL_ZDID AND BKFL_FDID=:BKFL_FDID';
end;

function TToDetail.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_TO_DETAIL'
         +'    ( BKFL_HDJE, BKFL_UNIT, BKFL_ZDID, BKFL_FDID, QBFL_HDJE'
         +'    , QBFL_UNIT, QBFL_ZDID, QBFL_FDID)'
         +'    VALUES'
         +'    (:BKFL_HDJE,:BKFL_UNIT,:BKFL_ZDID,:BKFL_FDID,:QBFL_HDJE'
         +'    ,:QBFL_UNIT,:QBFL_ZDID,:QBFL_FDID)';
end;

function TToDetail.GetStrsIndex: string;
begin
  Result:=Format('%S-%S-%D',[BKFLUNIT,BKFLZDID,BKFLFDID]);
end;

function TToDetail.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_TO_DETAIL SET'
         +'    QBFL_HDJE=:QBFL_HDJE,'
         +'    QBFL_UNIT=:QBFL_UNIT,'
         +'    QBFL_ZDID=:QBFL_ZDID,'
         +'    QBFL_FDID=:QBFL_FDID'
         +'    WHERE BKFL_HDJE=:BKFL_HDJE'
         +'    AND   BKFL_UNIT=:BKFL_UNIT'
         +'    AND   BKFL_ZDID=:BKFL_ZDID'
         +'    AND   BKFL_FDID=:BKFL_FDID';
end;

constructor TToDetail.Create;
begin

end;

destructor TToDetail.Destroy;
begin

  inherited;
end;

class function TToDetail.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TToDetail.Create;
  TToDetail.ReadDS(AUniQuery,Result);
end;

class procedure TToDetail.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TToDetail(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=UpperCase(Field.FieldName);
      if FieldName='BKFL_HDJE' then
      begin
        BKFLHDJE :=Field.AsFloat;
      end else
      if FieldName='BKFL_UNIT' then
      begin
        BKFLUNIT :=Field.AsString;
      end else
      if FieldName='BKFL_ZDID' then
      begin
        BKFLZDID :=Field.AsString;
      end else
      if FieldName='BKFL_FDID' then
      begin
        BKFLFDID :=Field.AsInteger;
      end else
      if FieldName='QBFL_HDJE' then
      begin
        QBFLHDJE :=Field.AsFloat;
      end else
      if FieldName='QBFL_UNIT' then
      begin
        QBFLUNIT :=Field.AsString;
      end else
      if FieldName='QBFL_ZDID' then
      begin
        QBFLZDID :=Field.AsString;
      end else
      if FieldName='QBFL_FDID' then
      begin
        QBFLFDID :=Field.AsInteger;
      end;
    end
  end;  
end;

class function  TToDetail.CopyIt(aToDetail: TToDetail): TToDetail;
begin
  Result:=TToDetail.Create;
  TToDetail.CopyIt(aToDetail,Result)
end;

class procedure TToDetail.CopyIt(aToDetail:TToDetail;var Result:TToDetail);
begin
  if Result=nil then Exit;
  Result.BKFLHDJE :=aToDetail.BKFLHDJE;
  Result.BKFLUNIT :=aToDetail.BKFLUNIT;
  Result.BKFLZDID :=aToDetail.BKFLZDID;
  Result.BKFLFDID :=aToDetail.BKFLFDID;
  Result.QBFLHDJE :=aToDetail.QBFLHDJE;
  Result.QBFLUNIT :=aToDetail.QBFLUNIT;
  Result.QBFLZDID :=aToDetail.QBFLZDID;
  Result.QBFLFDID :=aToDetail.QBFLFDID;
end;

end.

